home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!news1!basmith1
- From: basmith@iquest.net (Brian Smith)
- Subject: Initializing each element in an array of classes
- X-Nntp-Posting-Host: ind-001-236-87.iquest.net
- Message-ID: <4hssvm$178_001@basmith1.iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IDT
- X-Newsreader: News Xpress Version 1.0 Beta #4
- Date: Sat, 9 Mar 1996 21:19:43 GMT
-
- I have a Class called Dot that has X and Y among it's data members. It's
- constructor takes the initial values for X and Y as its parameters.
-
- class Dot {
- int X;
- int Y;
- Dot(void);
- Dot(int InitX, int InitY, int InitSize = 1) // default for InitSize is 1
- };
-
- Now I want to create another class Box that has as one of its data members an
- array of 3 Dots, and I want to initialize X and Y for all 3 of the Dots at the
- time class Box is created.
-
- class Box {
- int i;
- int j;
- Dot DotArray[3];
- etc...
- }
-
- The above code compiles, but the 3 Dots in DotArray are constructed using the
- default constructor (the one w/ no parameters). (I know this because I had to
- add it to get it to work.) So now I have 3 Dot objects, but with
- who-knows-what as their X and Y values.
-
- How can I create this array of Dots with the X and Y values of, for example,
- (1,1), (2,2), and (3,3)? The Borland Turbo C++ manual is of no help at all.
-
- Thanks,
-
- Brian Smith
-
-